import json
import logging

def load_config(config_path='config.json'):
    try:
        with open(config_path, 'r', encoding='utf-8') as f:
            config = json.load(f)
            
        # 验证必要配置项
        required_sections = ['redis', 'sftp', 'keys_to_read']
        for section in required_sections:
            if section not in config:
                raise ValueError(f'配置文件缺少必要部分: {section}')
        return config
    except Exception as e:
        logging.error(f'读取配置文件失败: {str(e)}', exc_info=True)
        # 返回默认配置
        return {
            'redis': {
                'host': 'localhost',
                'port': 6379,
                'password': '',
                'db': 0
            },
            'sftp': {
                'host': '10.96.177.24',
                'port': 2222,
                'username': 'xl',
                'password': '123456',
                'remote_dir': '/'
            },
            'keys_to_read': ['config_key1', 'config_key2', 'config_key3']
        }